//
//  BPLoginViewController.m
//  MVVM_Example
//
//  Created by 404 on 2020/11/17.
//  Copyright © 2020 xuhongji. All rights reserved.
//

#import "BPLoginViewController.h"
#import <ReactiveObjC/ReactiveObjC.h>
#import "BPLoginViewModel.h"

@interface BPLoginViewController ()
@property(nonatomic, strong) UIButton *button;
@property(nonatomic, strong) BPLoginViewModel *viewModel;
@end

@implementation BPLoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)mvvm_setupDefault{
    // 配置默认参数
    self.view.backgroundColor = [UIColor whiteColor];
    
}

- (void)mvvm_setupNavigationItems{
    // 配置导航栏
    //self.navigationController.navigationBarHidden = YES;
}

- (void)mvvm_initSubViews{
    // 初始化子控件
    [self.view addSubview:self.button];
}

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    // 更新UI布局
    self.button.center = self.view.center;
}

- (void)mvvm_bindViewModelForController{
    // 绑定数据
    @weakify(self);
    [[self.button rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        @strongify(self);
        [self.viewModel.pushCommand execute:nil];
    }];
}

#pragma mark - getter

- (UIButton *)button{
    if (!_button) {
        _button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 200, 40)];
        _button.backgroundColor = [UIColor redColor];
        [_button setTitle:@"jump to home" forState:UIControlStateNormal];
    }
    return _button;
}

@end
